﻿using System;
using System.Windows.Controls;
using System.Windows;
using Simp.CodeModel.Exceptions;

namespace Simp.Interpreter
{
	/// <summary>Error output control:  displays errors.</summary>
	public partial class ErrorOutputControl : UserControl
	{
		/// <summary>Constructor.</summary>
		public ErrorOutputControl()
		{
			InitializeComponent();
		}

		#region OriginalContent Property
		private static readonly DependencyProperty SimpExceptionProperty = DependencyProperty.Register(
			"SimpException",
			typeof(SimpRuntimeException),
			typeof(ErrorOutputControl),
			new UIPropertyMetadata(null, OnExceptionChanged));

		/// <summary>Exception to display.</summary>
		public SimpRuntimeException SimpException
		{
			get { return (SimpRuntimeException)GetValue(SimpExceptionProperty); }
			set { SetValue(SimpExceptionProperty, value); }
		}
		#endregion

		private static void OnExceptionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			ErrorOutputControl errorOutputControl = (ErrorOutputControl)d;

			errorOutputControl.Visibility = e.NewValue == null ? Visibility.Collapsed : Visibility.Visible;
		}
	}
}